<template>
  <div class="orderManage">
  <!-- 国际运输委托单管理 -->
  <div class="top">
  <div class="form">
       <el-form ref="form" :model="form" :rules="rule"  label-width="auto"  :inline="true" size="mini">

            <el-form-item prop="orderNum" label="订单号：">
              <el-input v-model="form.orderNum" clearable></el-input>
            </el-form-item>
            <el-form-item prop="orderStatue" label="订单状态：">
              <el-select v-model="form.orderStatue" clearable>
                  <el-option
                  v-for="(item,index) in statusList"
                  :key="index"
                  :value="item.rvLowValue"
                  :label="item.rvCmeaning"
                  >
                  </el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="start" label="下单时间：">
              <el-date-picker
              v-model="form.start"
              value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
             <el-form-item prop="end" label-width="3em" label="——">
              <el-date-picker
              v-model="form.end"
              value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
       <el-form-item prop="" label="">
        <el-button type="primary" size="mini" @click="searchList">查 询</el-button>
       </el-form-item>
      </el-form>
    </div>
    <div class="btn">
       <el-button plain size="mini" type="success" @click="addOrder">新增订单</el-button>
      <el-button plain size="mini" type="primary" @click="editOrder">修改订单</el-button>
      <el-button plain size="mini" type="danger" @click="delOrder">取消订单</el-button>
      <el-button plain size="mini" type="primary" @click="audit">订单审核</el-button>
      <el-button plain size="mini" type="info" @click="cancelAudit">取消审核</el-button>
    </div>
    <div class="name">订单信息列表</div>
    <div class="table" ref="inner">
      <el-table :data="tableData" border
          :height="maxHeight"
          :header-cell-style="{ textAlign: 'center' }"
          highlight-current-row
          @row-click="rowClick"
          @row-dblclick="dbrowClick"
          >
          <el-table-column :index="indexMethod" type="index"  align="center" label=" " width="50"></el-table-column>
          <el-table-column   align="left" prop="attCode"  label="订单号" show-overflow-tooltip  width="160"></el-table-column>
          <el-table-column   align="center" prop="attStatusName"  label="订单状态" show-overflow-tooltip  width="180"></el-table-column>
          <el-table-column   align="center" prop="attCreatetime"  label="下单时间" show-overflow-tooltip  width="180"></el-table-column>
          <el-table-column   align="left" prop="adcConsigner"  label="客户名称" show-overflow-tooltip  width="160"></el-table-column>
          <el-table-column   align="left" prop="adcLinkperson"  label="联系人" show-overflow-tooltip  width="160"></el-table-column>
          <el-table-column   align="left" prop="adcLinkphone"  label="联系电话" show-overflow-tooltip  width="160"></el-table-column>
          <el-table-column   align="left" prop="adcSAddress"  label="起始地" show-overflow-tooltip  width="200"></el-table-column>
          <el-table-column   align="left" prop="adcDAddress"  label="目的地" show-overflow-tooltip  width="200"></el-table-column>
          <el-table-column   align="left" prop="gdsName"  label="货物名称" show-overflow-tooltip  width="160"></el-table-column>
          <el-table-column   align="right" prop="gdsWeight"  label="订单总质量(T)" show-overflow-tooltip  width="160"></el-table-column>
          <el-table-column   align="right" prop="rmbamount"  label="订单金额(RMB)" show-overflow-tooltip  width="160"></el-table-column>
          <el-table-column   align="left" prop="attAuditor"  label="审核人" show-overflow-tooltip  width="160"></el-table-column>
          <el-table-column   align="center" prop="attAudittime"  label="审核时间" show-overflow-tooltip  width="180"></el-table-column>
          <el-table-column   align="left" prop="attAuditdiffering"  label="审核拒绝原因" show-overflow-tooltip  width="180"></el-table-column>
          <el-table-column   align="left" prop="attRemark"  label="备注" show-overflow-tooltip  width="180"></el-table-column>
      </el-table>
    </div>
    <div class="pages">
      <el-pagination
      ref="pagination"
      small
      background
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="Pagination.currentPage"
      :page-sizes="Pagination.pageSizeList"
      :page-size="Pagination.pageSize"
      :layout="Pagination.layout"
      :total="Pagination.total">
    </el-pagination>
    </div>
    </div>
    <div class="bottom">
      <div class="name">订单动态</div>
        <el-table :data="dynamicData" border
          height="300"
          :header-cell-style="{ textAlign: 'center' }"
          highlight-current-row
          >
          <el-table-column  type="index"  align="center" label=" " width="50"></el-table-column>
          <el-table-column   align="left" prop="optType"  label="操作类型" show-overflow-tooltip  width=""></el-table-column>
          <el-table-column   align="center" prop="optStatusName"  label="操作状态" show-overflow-tooltip  width=""></el-table-column>
          <el-table-column   align="left" prop="optCreator"  label="创建人" show-overflow-tooltip  width=""></el-table-column>
          <el-table-column   align="center" prop="optCreatetime"  label="创建时间" show-overflow-tooltip  width=""></el-table-column>
          <el-table-column   align="left" prop="optChanger"  label="最后修改人" show-overflow-tooltip  width=""></el-table-column>
          <el-table-column   align="center" prop="optChangetime"  label="最后修改时间" show-overflow-tooltip  width=""></el-table-column>
          <el-table-column   align="left" prop="optRemark"  label="备注" show-overflow-tooltip  width=""></el-table-column>
      </el-table>
    </div>
    <!-- 新增修改订单 对话框 -->
    <el-dialog
    :title="name"
    width="80%"
    :visible.sync="openDialog"
    v-if="openDialog"
    v-el-drag-dialog
    :before-close="close"
    :close-on-click-modal="false"
    >
      <div class="content">
        <div class="box">
          <div class="name">基础信息</div>
          <el-form :model="basicForm" :rules="basicRule" size="mini" ref="basicForm" label-width="auto">
            <el-row >
                <el-col :span="8">
                    <el-form-item label="客户：" prop="attCltId">
                      <el-select clearable v-model="basicForm.attCltId" :disabled="check || see" style="width:100%" @change="getName">
                        <el-option v-for="(item,index) in customer" :key="index" :value="item.cltId" :label="item.cltName"></el-option>
                      </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="委托人：" prop="adcConsigner">
                      <el-input clearable v-model="basicForm.adcConsigner" :disabled="check || see" maxlength="32"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row >
                <el-col :span="8">
                    <el-form-item label="联系人：" prop="adcLinkperson">
                      <el-input clearable v-model="basicForm.adcLinkperson" :disabled="check || see" maxlength="32"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="联系电话："  prop="adcLinkphone">
                      <el-input clearable v-model="basicForm.adcLinkphone" :disabled="check || see" maxlength="16"></el-input>
                    </el-form-item>
                </el-col>
                 <el-col :span="8">
                    <el-form-item label="手机：" prop="adcTel">
                      <el-input clearable v-model="basicForm.adcTel" :disabled="check || see" maxlength="11"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row >
               <el-col :span="8">
                    <el-form-item label="Email：" prop="adcEmail">
                      <el-input clearable v-model="basicForm.adcEmail" :disabled="check || see" maxlength="32"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="QQ：" prop="adcQq">
                      <el-input clearable v-model="basicForm.adcQq" :disabled="check || see" maxlength="32"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="微信："  prop="adcWechat">
                      <el-input clearable v-model="basicForm.adcWechat" :disabled="check || see" maxlength="32"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row >
                <el-col :span="8">
                    <el-form-item label="客户要求作业时间：" prop="attWrkdate">
                     <el-date-picker
                        clearable
                        :picker-options="startPickerOptions"
                        v-model="basicForm.attWrkdate"
                        value-format="yyyy-MM-dd"
                        :disabled="check || see"
                        >
                     </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="客户要求作业完成时间：" prop="attFinwrkdate">
                      <el-date-picker
                        clearable
                        :picker-options="endPickerOptions"
                        v-model="basicForm.attFinwrkdate"
                        value-format="yyyy-MM-dd"
                        :disabled="check || see"
                        >
                     </el-date-picker>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="车型要求："  prop="adcVehicleRequirements">
                      <el-select clearable v-model="basicForm.adcVehicleRequirements" :disabled="check || see" style="width:100%">
                        <el-option v-for="(item,index) in carType" :key="index" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
                      </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
             <el-row >
                <el-col :span="8">
                    <el-form-item label="卸车费支付方：" prop="adcXcfzff">
                     <el-select clearable v-model="basicForm.adcXcfzff" :disabled="check || see" style="width:100%">
                       <el-option v-for="(item,index) in payer" :key="index" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
                     </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="订单结算方式：" prop="adcJsfhValue">
                      <el-select clearable v-model="basicForm.adcJsfh" style="width:48%" :disabled="check || see" @change="getPay">
                        <el-option v-for="(item,index) in payWay" :key="index" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
                      </el-select>
                      <el-select v-model="basicForm.adcJsfhValue" style="width:48%;margin-left: 4%;" :disabled="check || see">
                        <el-option v-for="(item,index) in payTime" :key="index" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
                      </el-select>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="车长要求："  prop="trkLong">
                      <el-select clearable v-model="basicForm.trkLong" :disabled="check || see" style="width:100%">
                        <el-option v-for="(item,index) in carLong" :key="index" :label="item.rvCmeaning" :value="item.rvLowValue"></el-option>
                      </el-select>
                    </el-form-item>
                </el-col>
            </el-row>
          </el-form>
        </div>
        <div class="concate">
          <div class="send box">
            <div class="name">发货方信息</div>
            <concate-form :cltId="basicForm.attCltId" :compForm="sendForm" :desc="true" :view="view" ref='sendForm'></concate-form>
          </div>
           <div class="box accept">
              <div class="name">收货方信息</div>
              <concate-form :cltId="basicForm.attCltId" :compForm="acceptForm" :desc="false" :view="view" ref='acceptForm'></concate-form>
           </div>
        </div>
        <div class="box">
          <div class="name">获取里程</div>
          <el-form :model="distanceForm" :rules="distanceRule" size="mini" ref="distanceForm" label-width="auto">
            <el-row >
                <el-col :span="8">
                    <el-form-item label="里程：" prop="adcDistanced">
                      <el-input clearable v-model="distanceForm.adcDistanced" :disabled="check || see"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="8">
                    <el-form-item label="时间：" prop="adcDistancedtime">
                      <el-input clearable v-model="distanceForm.adcDistancedtime" :disabled="check || see"></el-input>
                    </el-form-item>
                </el-col>
                <el-col :span="2">
                  <el-link type="primary" @click="getJourney" :underline="false" v-if="!check && !see">获取里程</el-link>
                </el-col>
            </el-row>
          </el-form>
        </div>
        <div class="box">
          <div class="name">货物信息</div>
          <el-form :model="goodsForm[0]" size="mini" :rules="goodsRule" ref="goodsForm">
          <el-table
          :data="goodsForm"
          border
          height="150px"
          :header-cell-style="{ textAlign: 'center' }"
          highlight-current-row
          >
          <el-table-column  type="index"  align="center" label=" " width="50"></el-table-column>
          <el-table-column  align="center" prop="gdsType" label="货物类型" show-overflow-tooltip width="">
          <template slot-scope="scope">
             <el-form-item prop="gdsType">
            <el-select clearable style="width: 100%;" v-model="scope.row.gdsType" :disabled="check || see">
              <el-option  v-for="(item,index) in goods"
                  :key="index"
                  :value="item.rvLowValue"
                  :label="item.rvCmeaning"></el-option>
            </el-select>
             </el-form-item>
          </template>
          </el-table-column>
          <el-table-column  align="left" prop="gdsName" label="货名" show-overflow-tooltip width="">
          <template slot-scope="scope">
            <el-form-item prop="gdsName">
            <el-input clearable v-model="scope.row.gdsName" :disabled="check || see" ></el-input>
            </el-form-item>
          </template>
          </el-table-column>
           <el-table-column  align="left" prop="gdsQuantity" label="件数" show-overflow-tooltip width="140">
             <template slot-scope="scope">
               <el-form-item prop="gdsQuantity">
            <el-input clearable v-model="scope.row.gdsQuantity" :disabled="check || see"></el-input>
               </el-form-item>
          </template>
           </el-table-column>
            <el-table-column  align="left" prop="gdsWeight" label="重量(t)" show-overflow-tooltip width="">
              <template slot-scope="scope">
                 <el-form-item prop="gdsWeight">
              <el-input clearable v-model="scope.row.gdsWeight" :disabled="check || see"></el-input>
                 </el-form-item>
              </template>
            </el-table-column>
             <el-table-column  align="left" prop="gdsVolumn" label="体积(m³)" show-overflow-tooltip width="">
                <template slot-scope="scope">
                  <el-form-item prop="gdsVolumn">
              <el-input clearable v-model="scope.row.gdsVolumn" :disabled="check || see"></el-input>
                  </el-form-item>
              </template>
             </el-table-column>
              <el-table-column  align="left" prop="gdsPrice" label="吨/元" show-overflow-tooltip width="">
              <template slot-scope="scope">
                <el-form-item prop="gdsPrice">
                  <el-input clearable v-model="scope.row.gdsPrice" :disabled="check || see"></el-input>
                </el-form-item>
              </template>
              </el-table-column>
              <el-table-column  align="left" prop="gdsRemark" label="备注" show-overflow-tooltip width="130">
                <template slot-scope="scope">
                  <el-form-item prop="gdsRemark">
                     <el-input clearable v-model="scope.row.gdsRemark" :disabled="check || see || see"></el-input>
                  </el-form-item>
              </template>
              </el-table-column>
          </el-table>
          </el-form>
        </div>
       <div class="box" v-if="check">
          <div class="name">审核信息</div>
          <el-form :model="auditForm" :rules="auditRule" size="mini" ref="auditForm" label-width="auto">
            <el-row >
                <el-col :span="20">
                    <el-form-item label="审核意见：" prop="attAuditdiffering">
                      <el-input clearable v-model="auditForm.attAuditdiffering" type="textarea" :rows="2"></el-input>
                    </el-form-item>
                </el-col>
            </el-row>
          </el-form>
        </div>
      </div>
      <div slot="footer" class="dialog-footer" >
      <el-button type="primary" @click="save" v-if="!see" size="mini">保存</el-button>
      <el-button type="primary" @click="auditAction" v-if="check" size="mini">审核</el-button>
      <el-button type="primary" @click="rejectAction" v-if="check" size="mini">拒绝</el-button>
      <el-button  @click="close" size="mini">关闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import paginationMixin from '@/mixins/pagination'
import resizeMixin from '@/mixins/resize'
import concateForm from './concate'
import {orderInfo,orderOperaInfo,addOrEditOrderInfo,getRefCodesByType,
  getAuditUserList,EditOrderInfo,auditOrder,cancleOrderInfo,} from '@/request/api'
import { PATTERN } from '@/utils/rules'

export default {
  mixins:[paginationMixin,resizeMixin],
  components:{concateForm},
  data(){
    return{
      form:{
        orderNum:'',
        orderStatue:'',
        start:'',
        end:''
      },
      rule:{
        orderNum:[],
        orderStatue:[],
        start:[],
      },
      statusList:[],//状态值
      maxHeight:-1,
      tableData:[],
      dynamicData:[],//动态数据
      currentData:{},//单击选中数据
      viewData:{},//双击选中数据

      //对话框----新增修改
      name:'',
      openDialog:false,
      edit:false,//编辑
      see:false,//查看
      check:false,//审核
      view:'0',
      distanceForm:{},//里程信息
      distanceRule:{
        adcDistanced:[{required:true,message:'请输入里程',trigger:'blur'}],
        adcDistancedtime:[{required:true,message:'请输入时间',trigger:'blur'}],
      },
      basicForm:{},//基础信息
      basicRule:{
        attCltId:[{required:true,message:'请选择客户名称',trigger:'change'}],
        adcConsigner:[{required:true,message:'请输入委托人',trigger:'blur'}],
        adcLinkperson:[{required:true,message:'请输入联系人',trigger:'blur'}],
        adcLinkphone:[{required:true,message:'请输入联系电话',trigger:'blur'}],
        adcTel:[{required:true,message:'请输入手机号',trigger:'blur'}],
        adcEmail:[
          {required:true,message:'请输入Email地址',trigger:'blur'},
          { pattern: PATTERN.EMAIL, message:'请输入正确的Email地址',trigger:'blur'}
        ],
        adcQq:[{required:false,message:'请输入QQ',trigger:'blur'}],
        adcWechat:[{required:false,message:'请输入微信',trigger:'blur'}],
        attWrkdate:[{required:true,message:'请输入客户要求作业时间',trigger:'blur'}],
        attFinwrkdate:[{required:true,message:'请输入客户要求作业完成时间',trigger:'blur'}],
        adcVehicleRequirements:[{required:true,message:'请输入车型要求',trigger:'blur'}],
        adcXcfzff:[{required:true,message:'请输入卸车支付方',trigger:'blur'}],
        adcJsfhValue:[{required:true,message:'请输入订单结算方式',trigger:'change'}],
        trkLong:[{required:true,message:'请输入车长要求',trigger:'blur'}],
      },
      customer:[],//客户
      carType:[],//车型
      payer:[],//卸车支付
      payWay:[],//结算方式
      payTime:[],//结算方式
      carLong:[],//车长
      goods:[],
      sendForm:{},//发货信息
      acceptForm:{},//收货信息
      concateRule:{

      },
      goodsForm:[],//货物信息
      goodsRule:{
        gdsType:[{required:true,message:'请选择货物类型',trigger:'blur'}],
        gdsName:[{required:true,message:'请输入货物名称',trigger:'blur'}],
        gdsQuantity:[{required:true,message:'请输入货物件数',trigger:'blur'}],
        gdsWeight:[{required:true,message:'请输入货物质量',trigger:'blur'}],
        gdsVolumn:[{required:true,message:'请输入货物体积',trigger:'blur'}],
        gdsPrice:[{required:true,message:'请输入货物价格',trigger:'blur'}],
      },
      //审核信息
      auditForm:{attAuditdiffering:''},
      auditRule:{},
    }

  },
  mounted(){
    this.refreshList()


    //订单状态
    getRefCodesByType('网络平台订单状态').then(res=>{
      if(res.success==='1'){
        this.statusList=res.data.FTKJWLHYPT
      }
    })
    getRefCodesByType('网络平台货物类型').then(res=>{
      if(res.success==='1'){
        this.goods=res.data.FTKJWLHYPT
      }
    })
    getRefCodesByType('卸车费用付方').then(res=>{
      if(res.success==='1'){
        this.payer=res.data.FTKJWLHYPT
      }
    })
    getRefCodesByType('车型_网络').then(res=>{
      if(res.success==='1'){
        this.carType=res.data.FTKJWLHYPT
      }
    })
    getRefCodesByType('车长_网络').then(res=>{
      if(res.success==='1'){
        this.carLong=res.data.FTKJWLHYPT
      }
    })
    getRefCodesByType('网络_结算方式').then(res=>{
      if(res.success==='1'){
        this.payWay=res.data.FTKJWLHYPT
      }
    })
    //客户下拉框
    getAuditUserList().then(res=>{
      if(res.success==='1'){
        this.customer=res.data.FTKJWLHYPT
      }
    })
  },
  created(){
    this.resize=()=>{
      this.maxHeight=this.$refs.inner.offsetHeight
    }
  },
  computed: {
    startPickerOptions () {
      return {
        disabledDate: (date) => {
          if (!this.basicForm.attFinwrkdate) return false
          return (date.getTime()) > (new Date(this.basicForm.attFinwrkdate).getTime())
        }
      }
    },
    endPickerOptions () {
      return {
        disabledDate: (date) => {
          if (!this.basicForm.attWrkdate) return false
          return (date.getTime()) < (new Date(this.basicForm.attWrkdate).getTime())
        }
      }
    }
  },
  watch:{
    basicForm:{
      handler(){
        this.getPay(this.basicForm.adcJsfh)
      }
    }
  },
  methods:{
    //拒绝
    rejectAction(){
      auditOrder({
        uuid:this.currentData.uuid,
        attStatus:'SHJJ',
        attCode:this.currentData.attCode,
        attAuditdiffering:this.auditForm.attAuditdiffering
      }).then(res=>{
        if(res.success==='1'){
          this.$message({
            type:'success',
            message:'拒绝成功'
          })
          this.close()
        }
      })
    },
    //审核
    auditAction(){

      auditOrder({
        uuid:this.currentData.uuid,
        attStatus:'YSH',
        attCode:this.currentData.attCode,
        attAuditdiffering:this.auditForm.attAuditdiffering
      }).then(res=>{
        if(res.success==='1'){
          this.$message({
            type:'success',
            message:'审核成功'
          })
          this.close()
        }
      })
    },
    //获取结算类型
    getPay(name){
      // this.basicForm.adcJsfhValue=''
      this.payTime=[]
      getRefCodesByType(name).then(res=>{
        if(res.success==='1'){
          this.payTime=res.data.FTKJWLHYPT
        }
      })
    },
    //获取客户name
    getName(name){
      // console.log(name)
      // this.basicForm.attCltName=name
      this.customer.forEach(item=>{
        if(item.cltId===name){
          this.basicForm.attCltName=item.cltName
          this.basicForm.attCEtpId=item.cltEptId
          this.basicForm.adcConsigner = item.cltName
          this.basicForm.adcLinkperson = item.cltContact
          this.basicForm.adcLinkphone = item.cltCtctel
          this.basicForm.adcTel = item.cltCtctel
        }
      })
    },
    //查询
    searchList(){
      this.refreshList()
    },
    //重写getList
    getList(currentPage, pageSize, updateTotal) {
      orderInfo({
        attCode: this.form.orderNum,
        attStatus: this.form.orderStatue,
        attCreatetimeStart:this.form.start,
        attCreatetimeEnd:this.form.end,
        PageIndexs:this.Pagination.currentPage.toString(),
        PageSizes:this.Pagination.pageSize.toString()
      }).then(response => {
        this.tableData = response.data.FTKJWLHYPT
        updateTotal(Number(response.data.total.FTKJWLHYPT))
      })
    },
    //计算里程
    getJourney(){
      var lng=this.sendForm.jd
      var lat=this.sendForm.wd
      var lng1=this.acceptForm.jd
      var lat1=this.acceptForm.wd

      if (!lng || !lat || !lng1 || !lat1) return

      this.searchTransit({lng,lat},{lng:lng1,lat:lat1},this.searchComplete,'北京')
    },
    searchTransit(startPoint, endPoint, searchComplete, map) {
      var BMap=window.BMap
      var start = new BMap.Point(startPoint.lng, startPoint.lat)
      var end = new BMap.Point(endPoint.lng, endPoint.lat)
      var transit = new BMap.DrivingRoute(map, {
        onSearchComplete: searchComplete
      })
      transit.search(start, end)

    },
    searchComplete(results){
      var output , time =''
      var plan = results.getPlan(0)
      time = plan.getDuration(true)             //获取时间

      output = plan.getDistance(true)   //获取距离

      this.distanceForm.adcDistanced=output
      this.distanceForm.adcDistancedtime=time

    },
    //保存编辑 新增
    save(){
      const basic=new Promise((resolve, reject) => {
        this.$refs.basicForm.validate(valid => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        })
      })

      const send=new Promise((resolve, reject)=>{
        // console.log(this.$refs.sendForm)
        this.$refs.sendForm.validate(valid => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        })
      })

      const accept=new Promise((resolve, reject)=>{
        this.$refs.acceptForm.validate(valid => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        })
      })

      const distance=new Promise((resolve, reject)=>{
        this.$refs.distanceForm.validate(valid => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        })
      })

      const goods=new Promise((resolve, reject)=>{
        // if(this.goodsForm.length>0){
        //   resolve()
        // }else{
        //   reject()
        // }
        console.log(this.$refs.goodsForm)
        this.$refs.goodsForm.validate(valid => {
          if (valid) {
            resolve()
          } else {
            reject()
          }
        })
      })
      // console.log(goods)
      Promise.all([
        basic,
        send,
        accept,
        distance,
        goods
      ]).then(()=>{

        if(this.edit){
        //编辑
          EditOrderInfo({
            uuid:this.basicForm.uuid,
            attCltId:this.basicForm.attCltId,//客户ID
            attCltName:this.basicForm.attCltName,//attCltName
            attCEtpId:this.basicForm.attCEtpId,//客户企业ID
            attRemark:this.basicForm.attRemark,//备注
            odcSProvince:this.sendForm.province,//发货地省
            orDeliverypointcity:this.sendForm.city,//发货地市
            adcSAddress:this.sendForm.xxdz,//发货地详细地址
            odcDProvince:this.acceptForm.province,//收货方省
            orReveivingpartytelcity:this.acceptForm.city,//收货方市
            adcDAddress:this.acceptForm.xxdz,//收货方详细地址
            attWrkdate:this.basicForm.attWrkdate,//客户要求作业时间
            attFinwrkdate:this.basicForm.attFinwrkdate,//客户要求完成时间
            adcVehicleRequirements:this.basicForm.adcVehicleRequirements,//车型

            adcCltId:this.sendForm.adcCltId,//客户ID
            adcConsigner:this.basicForm.adcConsigner,//委托人
            adcLinkperson:this.basicForm.adcLinkperson,//联系人
            adcLinkphone:this.basicForm.adcLinkphone,//联系电话
            adcTel:this.basicForm.adcTel,//手机
            adcQq:this.basicForm.adcQq,//QQ,
            adcWechat:this.basicForm.adcWechat,//微信
            adcEmail:this.basicForm.adcEmail,//EMAIL
            orReveivingparty:this.acceptForm.orReveivingparty, //收货方
            orReveivingpartycontacts:this.acceptForm.lxr,//收货方联系人
            orReveivingpartytel:this.acceptForm.lxdh,//收货方联系方式
            orShipper:this.sendForm.orShipper,//发货方

            orShippercontacts:this.sendForm.lxr,//发货方联系人
            orShippertel:this.sendForm.lxdh,//发货方联系方式
            odcSArea:this.sendForm.district,//发货地区县
            odcDArea:this.acceptForm.district,//收货地区县
            trkLong:this.basicForm.trkLong,//车长要求
            adcSX:this.sendForm.jd,//X坐标--发
            adcSY:this.sendForm.wd,//Y坐标
            adcSSwrkdate:this.sendForm.adcSSwrkdate, //装车时间段（开始）
            adcSEwrkdate:this.sendForm.adcSEwrkdate, //装车时间段（结束）
            adcDX:this.acceptForm.jd, //X坐标---收
            adcDY:this.acceptForm.wd, //Y坐标
            adcDSfinwrkdate:this.acceptForm.adcDSfinwrkdate, //卸车时间段（开始）
            adcDEfinwrkdate:this.acceptForm.adcDEfinwrkdate,  //卸车时间段（结束）
            adcXcfzff:this.basicForm.adcXcfzff, //卸车费支付方（RV_DOMAIN=‘卸车费用付方’）
            adcJsfh:this.basicForm.adcJsfh, //结算方式
            adcJsfhValue:this.basicForm.adcJsfhValue, //结算类型
            adcDistanced:this.distanceForm.adcDistanced, //里程
            adcDistancedtime:this.distanceForm.adcDistancedtime, //运输时间

            //货物
            gdsPrice: this.goodsForm[0].gdsPrice,
            gdsName:this.goodsForm[0].gdsName,
            gdsType:this.goodsForm[0].gdsType,
            gdsQuantity:this.goodsForm[0].gdsQuantity,
            gdsWeight:this.goodsForm[0].gdsWeight,
            gdsVolumn:this.goodsForm[0].gdsVolumn,
            gdsRemark:this.goodsForm[0].gdsRemark,
          }).then(res=>{
            if(res.success==='1'){
              this.$message({
                type:'success',
                message:'修改数据成功',
                showClose:true
              })
              this.close()
            }
          })
        }else{
        //新增

          addOrEditOrderInfo(
            {
              attCltId:this.basicForm.attCltId,//客户ID
              attCltName:this.basicForm.attCltName,//attCltName
              attCEtpId:this.basicForm.attCEtpId,//客户企业ID
              attRemark:this.basicForm.attRemark,//备注
              odcSProvince:this.sendForm.province,//发货地省
              orDeliverypointcity:this.sendForm.city,//发货地市
              adcSAddress:this.sendForm.xxdz,//发货地详细地址
              odcDProvince:this.acceptForm.province,//收货方省
              orReveivingpartytelcity:this.acceptForm.city,//收货方市
              adcDAddress:this.acceptForm.xxdz,//收货方详细地址
              attWrkdate:this.basicForm.attWrkdate,//客户要求作业时间
              attFinwrkdate:this.basicForm.attFinwrkdate,//客户要求完成时间
              adcVehicleRequirements:this.basicForm.adcVehicleRequirements,//车型

              adcCltId:this.sendForm.adcCltId,//客户ID
              adcConsigner:this.basicForm.adcConsigner,//委托人
              adcLinkperson:this.basicForm.adcLinkperson,//联系人
              adcLinkphone:this.basicForm.adcLinkphone,//联系电话
              adcTel:this.basicForm.adcTel,//手机
              adcQq:this.basicForm.adcQq,//QQ,
              adcWechat:this.basicForm.adcWechat,//微信
              adcEmail:this.basicForm.adcEmail,//EMAIL
              orReveivingparty:this.acceptForm.orReveivingparty, //收货方
              orReveivingpartycontacts:this.acceptForm.lxr,//收货方联系人
              orReveivingpartytel:this.acceptForm.lxdh,//收货方联系方式
              orShipper:this.sendForm.orShipper,//发货方
              orShippercontacts:this.sendForm.lxr,//发货方联系人
              orShippertel:this.sendForm.lxdh,//发货方联系方式
              odcSArea:this.sendForm.district,//发货地区县
              odcDArea:this.acceptForm.district,//收货地区县
              trkLong:this.basicForm.trkLong,//车长要求
              adcSX:this.sendForm.jd,//X坐标--发
              adcSY:this.sendForm.wd,//Y坐标
              adcSSwrkdate:this.sendForm.adcSSwrkdate, //装车时间段（开始）
              adcSEwrkdate:this.sendForm.adcSEwrkdate, //装车时间段（结束）
              adcDX:this.acceptForm.jd, //X坐标---收
              adcDY:this.acceptForm.wd, //Y坐标
              adcDSfinwrkdate:this.acceptForm.adcDSfinwrkdate, //卸车时间段（开始）
              adcDEfinwrkdate:this.acceptForm.adcDEfinwrkdate,  //卸车时间段（结束）
              adcXcfzff:this.basicForm.adcXcfzff, //卸车费支付方（RV_DOMAIN=‘卸车费用付方’）
              adcJsfh:this.basicForm.adcJsfh, //结算方式
              adcJsfhValue:this.basicForm.adcJsfhValue, //结算类型
              adcDistanced:this.distanceForm.adcDistanced, //里程
              adcDistancedtime:this.distanceForm.adcDistancedtime, //运输时间

              //货物
              gdsPrice: this.goodsForm[0].gdsPrice,
              gdsName:this.goodsForm[0].gdsName,
              gdsType:this.goodsForm[0].gdsType,
              gdsQuantity:this.goodsForm[0].gdsQuantity,
              gdsWeight:this.goodsForm[0].gdsWeight,
              gdsVolumn:this.goodsForm[0].gdsVolumn,
              gdsRemark:this.goodsForm[0].gdsRemark,
            }
          ).then(res=>{
            if(res.success==='1'){
              this.$message({
                type:'success',
                message:'新增数据成功',
                showClose:true
              })
              this.close()
            }
          })

        }
      })


    },
    //关闭对话框----新增编辑查看
    close(){
      this.openDialog=false
      this.refreshList()
    },
    //双击查看详情
    dbrowClick(row){
      this.currentData=Object.assign({},row)
      this.basicForm = this.currentData
      //收货
      this.acceptForm={
        orReveivingparty:this.currentData.orReveivingparty,
        lxr:this.currentData.orReveivingpartycontacts,
        lxdh:this.currentData.orReveivingpartytel,
        adcDSfinwrkdate:this.currentData.adcDSfinwrkdate,
        adcDEfinwrkdate:this.currentData.adcDEfinwrkdate,
        province:this.currentData.odcDProvince,
        city:this.currentData.orReveivingpartytelcity,
        district:this.currentData.odcDArea,
        xxdz:this.currentData.adcDAddress,
        jd:this.currentData.adcDX,
        wd:this.currentData.adcDY
      }
      //发货
      this.sendForm={
        orShipper:this.currentData.orShipper,
        lxr:this.currentData.orShippercontacts,
        lxdh:this.currentData.orShippertel,
        adcSSwrkdate:this.currentData.adcSSwrkdate,
        adcSEwrkdate:this.currentData.adcSEwrkdate,
        province:this.currentData.odcSProvince,
        city:this.currentData.orDeliverypointcity,
        district:this.currentData.odcSArea,
        xxdz:this.currentData.adcSAddress,
        jd:this.currentData.adcSX,
        wd:this.currentData.adcSY
      }
      this.distanceForm=this.currentData
      this.goodsForm[0]=this.currentData
      this.auditForm={}
      this.check=false
      this.view='1'
      this.openDialog=true
      this.edit=false
      this.see=true
      this.name='查看订单'
    },
    //单击
    rowClick(row){
      setTimeout(() => {
        this.currentData=Object.assign({},row)

        this.getDynamic()
      }, 300)

    },
    //获取动态信息
    getDynamic(){
      orderOperaInfo({attUuid:this.currentData.uuid}).then(res=>{
        if(res.success==='1'){
          this.dynamicData=res.data.FTKJWLHYPT
        }
      })
    },
    //取消审核
    cancelAudit(){
      if(Object.keys(this.currentData).length===0){
        this.$alert('每次只能修改一行数据，你已选择0行','提示',{
          confirmButtonText:'确定'
        })
        return
      }

      if(this.currentData.attStatus!='YSH'){
        this.$alert('该订单不是未审核，无法取消审核！','提示',{
          confirmButtonText:'确定'
        })
        return
      }
      auditOrder({
        uuid:this.currentData.uuid,
        attStatus:'QXSH',
        attCode:this.currentData.attCode,
        attAuditdiffering:''
      }).then(res=>{
        if(res.success==='1'){
          this.$message({
            type:'success',
            message:'取消审核成功'
          })
          this.close()
        }
      })

    },
    //审核
    audit(){
      if(Object.keys(this.currentData).length===0){
        this.$alert('每次只能修改一行数据，你已选择0行','提示',{
          confirmButtonText:'确定'
        })
        return
      }

      if(this.currentData.attStatus!='CS'){
        this.$alert('该订单不是未审核状态，无法审核！','提示',{
          confirmButtonText:'确定'
        })
        return
      }

      this.basicForm=this.currentData
      //收货
      this.acceptForm={
        orReveivingparty:this.currentData.orReveivingparty,
        lxr:this.currentData.orReveivingpartycontacts,
        lxdh:this.currentData.orReveivingpartytel,
        adcDSfinwrkdate:this.currentData.adcDSfinwrkdate,
        adcDEfinwrkdate:this.currentData.adcDEfinwrkdate,
        province:this.currentData.odcDProvince,
        city:this.currentData.orReveivingpartytelcity,
        district:this.currentData.odcDArea,
        xxdz:this.currentData.adcDAddress,
        jd:this.currentData.adcDX,
        wd:this.currentData.adcDY
      }
      //发货
      this.sendForm={
        orShipper:this.currentData.orShipper,
        lxr:this.currentData.orShippercontacts,
        lxdh:this.currentData.orShippertel,
        adcSSwrkdate:this.currentData.adcSSwrkdate,
        adcSEwrkdate:this.currentData.adcSEwrkdate,
        province:this.currentData.odcSProvince,
        city:this.currentData.orDeliverypointcity,
        district:this.currentData.odcSArea,
        xxdz:this.currentData.adcSAddress,
        jd:this.currentData.adcSX,
        wd:this.currentData.adcSY
      }
      this.distanceForm=this.currentData
      this.goodsForm[0]=this.currentData
      this.auditForm={}
      this.check=true
      this.view='1'
      this.openDialog=true
      this.edit=false
      this.see=true
      this.name='确认审核'
    },
    //取消订单
    delOrder(){
      if(Object.keys(this.currentData).length===0){
        this.$alert('每次只能修改一行数据，你已选择0行','提示',{
          confirmButtonText:'确定'
        })
        return
      }

      this.$alert('注意：你确定取消该订单吗？取消后不可恢复！','提示',{
        confirmButtonText:'确定',
        cancelButtonText:'取消'
      }).then(()=>{
        cancleOrderInfo({
          uuid:this.currentData.uuid,
          attCode:this.currentData.attCode
        }).then(res=>{
          if(res.success==='1'){
            this.$message({
              type:'success',
              message:'订单取消成功！'
            })
            this.close()
          }
        })
      })
    },
    //修改
    editOrder(){
      if(Object.keys(this.currentData).length===0){
        this.$alert('每次只能修改一行数据，你已选择0行','提示',{
          confirmButtonText:'确定'
        })
        return
      }
      if(this.currentData.attStatus!='CS'){
        this.$alert('未审核的订单才能编辑，无法编辑！','提示',{
          confirmButtonText:'确定'
        })
        return
      }

      this.basicForm=this.currentData
      // console.log(this.basicForm)
      //收货
      this.acceptForm={
        orReveivingparty:this.currentData.orReveivingparty || '',
        lxr:this.currentData.orReveivingpartycontacts || '',
        lxdh:this.currentData.orReveivingpartytel || '',
        adcDSfinwrkdate:this.currentData.adcDSfinwrkdate || '',
        adcDEfinwrkdate:this.currentData.adcDEfinwrkdate || '',
        province:this.currentData.odcDProvince || '',
        city:this.currentData.orReveivingpartytelcity || '',
        district:this.currentData.odcDArea || '',
        xxdz:this.currentData.adcDAddress || '',
        jd:this.currentData.adcDX || '',
        wd:this.currentData.adcDY || ''
      }
      //发货
      this.sendForm={
        orShipper:this.currentData.orShipper || '',
        lxr:this.currentData.orShippercontacts || '',
        lxdh:this.currentData.orShippertel || '',
        adcSSwrkdate:this.currentData.adcSSwrkdate || '',
        adcSEwrkdate:this.currentData.adcSEwrkdate || '',
        province:this.currentData.odcSProvince || '',
        city:this.currentData.orDeliverypointcity || '',
        district:this.currentData.odcSArea || '',
        xxdz:this.currentData.adcSAddress || '',
        jd:this.currentData.adcSX || '',
        wd:this.currentData.adcSY || ''
      }
      this.distanceForm=this.currentData
      this.goodsForm[0]=this.currentData
      this.openDialog=true
      this.edit=true
      this.see=false
      this.check=false
      this.view='0'
      this.name='编辑订单信息'
    },
    //新增
    addOrder(){

      this.basicForm={
        adcCltId:'',
        adcConsigner:'',
        adcLinkperson:'',
        adcLinkphone:'',
        adcEmail:'',
        adcQq:'',
        adcWechat:'',
        attWrkdate:'',
        attFinwrkdate:'',
        adcVehicleRequirements:'',
        adcXcfzff:'',
        adcJsfh:'',
        trkLong:'',
      }
      //收货
      this.acceptForm={
        orReveivingparty:'',
        lxr:'',
        lxdh:'',
        adcDSfinwrkdate:'',
        adcDEfinwrkdate:'',
        province:'',
        city:'',
        district:'',
        xxdz:'',
        jd:'',
        wd:''
      }
      //发货
      this.sendForm={
        orShipper:'',
        lxr:'',
        lxdh:'',
        adcSSwrkdate:'',
        adcSEwrkdate:'',
        province:'',
        city:'',
        district:'',
        xxdz:'',
        jd:'',
        wd:''
      }
      this.distanceForm={
        adcDistancedtime:'',
        adcDistanced:'',
      }
      this.goodsForm=[{
        gdsType:'',
        gdsName:'',
        gdsQuantity:'',
        gdsWeight:'',
        gdsVolumn:'',
        dw:'',
        gdsRemark:''
      }]
      this.openDialog=true
      this.edit=false
      this.see=false
      this.check=false
      this.view='0'
      this.name='新增订单信息'
    }
  }

}
</script>
<style lang="scss" scoped>
.orderManage{
  padding:15px 15px 12px;
  height:100%;
  width:100%;
  .top{
    height:400px;
    display:flex;
    flex-direction: column;
  .form{
    height:30px;
  }
  .btn{
    height:50px;
    line-height:50px;
  }
  .name{
    font-size:16px;
    line-height:20px;
    font-weight:500;
  }
  .table{
    flex:1;
  }
.pages{
  height:30px;
}
  }
  .bottom{
    height:300px;
    .name{
    font-size:16px;
    line-height:20px;
    font-weight:500;
    }
  }

.concate{
  display:flex;
  justify-content: space-between;
  // padding:10px 0;
  .send{
    width:49%;
  }
  .accept{
    width:49%;
  }
}
  .box{
    padding:12px;
    position:relative;
    border:1px solid rgb(29, 158, 233);
    border-radius:5px;
    // height:300px;
    margin-bottom:20px;
    .name{
      position: absolute;
      top:-20px;
      font-size:16px;
      font-weight:700;
      padding:10px;
      line-height:20px;
      background:#fff;
    }
  }
}
</style>
